﻿namespace XRepair.Conventions
{
    using System;
    using System.ComponentModel;

    public static class PropAttResolver<T>
        where T : IConvertible
    {
        public static string GetDescription(T field)
        {
            if (typeof(T).IsEnum)
            {
                var fieldInfo = field.GetType().GetField(field.ToString());
                var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
                return (attributes.Length > 0) ? attributes[0].Description : field.ToString();
            }

            return string.Empty;
        }
    }
}
